#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : bigDataProject 
@File    : baseRequestsDto.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/11/14 15:44 
@Describe: 接口请求数据模型基类
"""
from typing import Optional, Text
from pydantic import BaseModel, validator

from model.enum.brand_info_enum import get_brand_code_list


class BaseRequestDTO(BaseModel):
    brandCode: Optional[Text]
    env: Optional[Text]

    @validator("brandCode",  always=True)
    def brand_code_rule(cls, values):
        """校验brandCode参数"""

        def is_valid(brand_code):
            if len(brand_code) != 6:
                return False
            if brand_code not in get_brand_code_list():
                return False
            return True

        if not is_valid(values):
            raise ValueError("brandCode参数输入有误,请检查后重试~")
        return values

    @validator("env",  always=True)
    def env_rule(cls, Env: Text):
        env_list = ["sit", "uat", "prod"]

        def is_valid(env):
            if len(env) < 3 or len(env) > 4:
                return False
            if env not in env_list:
                return False
            return True

        if not is_valid(Env.lower()):
            raise ValueError("env参数输入有误,请检查后重试~")
        return Env


if __name__ == '__main__':
    test = BaseRequestDTO(brandCode='823882', env='sit')
    print(test)
